package com.zhicheng.backend.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zhicheng.backend.common.Result;
import com.zhicheng.backend.entity.Article;
import com.zhicheng.backend.service.ArticleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 功能: 文章控制器
 * 作者:YukiSu
 * 日期:2024/11/28 21:05
 */
@RestController
@RequestMapping("/article")
public class ArticleController {

    ArticleService articleService;
    @Autowired
    public ArticleController(ArticleService articleService) {
        this.articleService = articleService;
    }
    @GetMapping("/all")
    public Result listArticle() {

        return Result.success("测试成功");
    }
    @GetMapping("/articleList")
    public Result getArticlesListByPage(@RequestParam Integer currentPage) {
        IPage<Article> page = new Page<>(currentPage, 8);
        IPage<Article> articleIPage = articleService.page(page);
        return Result.success(articleIPage.getRecords());
    }
//    通过aid获取文章
    @GetMapping("/{aid}")
    public Result getArticleByAid(@PathVariable Integer aid) {
        return Result.success(articleService.getById(aid));
    }

//    获取文章总数
    @GetMapping("/count")
    public Result getArticlesTotalNum() {
        return Result.success(articleService.count());
    }

}